import cv2

# 打开默认摄像头
cap = cv2.VideoCapture(0)

while True:
    # 逐帧捕获视频
    ret, frame = cap.read()

    # 显示视频
    cv2.imshow('Video', frame)

    # 按 'q' 键退出
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# 释放摄像头并关闭窗口
cap.release()
cv2.destroyAllWindows()